<template>

    <div>
        <div>
            <!-- 添加修改跟进  房源 -->
            <el-form :model="followform" ref="followform" inline size="mini" :rules="followrules" v-if="this.resourcesdata == 1 || this.business == 1">
                <div>
                    <el-form-item label="跟进时间" v-if="this.followsearch.type">
                        <el-input  :value="followform.f_created_at" readonly class="normal_inp"></el-input>
                    </el-form-item>
                    <el-form-item label="跟进方式" prop="f_follow_up_way">
                        <el-select v-model="followform.f_follow_up_way" placeholder="请选择" class="normal_inp" @change="changetype" :disabled="editreadonly">
                            <el-option v-for="(item,index) in follow_up_way" :key="index" :label="item.value" :value="item.id" :disabled="item.disabled"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="跟进员工" prop="f_department_id" class="normal_inp">
                        <el-select v-model="followform.f_department_id" placeholder="请选择" @change="obtainuser" :disabled="editreadonly">
                            <!-- <el-option v-for="(item,index) in optionName" :key="index" :label="item.name" :value="item.id"></el-option> -->
                            <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                                <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-option-group>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="" prop="f_user_id" class="normal_inp">
                        <el-select v-model="followform.f_user_id" placeholder="请选择" :disabled="editreadonly">
                            <el-option v-for="(item,index) in usertypes" :key="index" :label="item.u_username" :value="item.u_id"></el-option>
                        </el-select>
                    </el-form-item>
                </div> 
                <div>
                    <el-form-item label="看房客源" v-if="followform.f_follow_up_way == 3">
                        <el-input placeholder="请选择" :value="choose_info_str" class="normal_inp" style="width:384px;" readonly>
                            <el-button slot="append" @click="choose_housing" :disabled="editreadonly">选择</el-button>
                        </el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="跟进内容" prop="f_content">
                        <el-input type="textarea" v-model="followform.f_content" class="normal_inp" :readonly="editreadonly"></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="下次提醒" prop="cfs_remind_time">
                        <el-date-picker v-model="followform.cfs_remind_time" type="date" placeholder="选择日期" class="normal_inp" value-format="yyyy-MM-dd" @change="changedate" :disabled="editreadonly"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="提醒范围" prop="cfs_user_id">
                        <el-select v-model="followform.cfs_user_id" placeholder="请选择" class="normal_inp" :disabled="!remind">
                            <el-option v-for="(item,index) in cfs_user" :key="index" :label="item.value" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="提醒内容" prop="cfs_content">
                        <el-input type="textarea" v-model="followform.cfs_content" class="normal_inp" :readonly="!remind"></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="" prop="cfs_deal_with">
                        <el-checkbox v-model="followform.cfs_deal_with" @change="dealchange" :disabled="business == 3">我知道了</el-checkbox>
                    </el-form-item>
                    <el-form-item label="处理" prop="cfs_dealwith_pro">
                        <el-input class="normal_inp" v-model="followform.cfs_dealwith_pro" readonly></el-input>
                    </el-form-item>
                    <el-form-item label="" prop="cfs_dealwith_time">
                        <el-input class="normal_inp" v-model="followform.cfs_dealwith_time" readonly></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="经理点评" prop="cfs_manager_review">
                        <el-input type="textarea" v-model="followform.cfs_manager_review" class="normal_inp" :readonly="managerReview"></el-input>
                    </el-form-item>
                </div>
            </el-form>
            <!-- 添加修改跟进  客源 -->
            <el-form :model="cfollowform" ref="cfollowform" inline size="mini" :rules="cfollowrules" v-if="this.resourcesdata == 2 || this.business == 2">
                <div>
                    <el-form-item label="跟进时间" v-if="this.followsearch.type">
                        <el-input :value="cfollowform.cf_created_at" readonly class="normal_inp"></el-input>
                    </el-form-item>
                    <el-form-item label="跟进方式" prop="cf_fllow_type">
                        <el-select v-model="cfollowform.cf_fllow_type" placeholder="请选择" class="normal_inp" :disabled="editreadonly">
                            <el-option v-for="(item,index) in follow_up_way" :key="index" :label="item.value" :value="item.id" :disabled="item.disabled"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="跟进员工" prop="cf_department_id" class="normal_inp">
                        <el-select v-model="cfollowform.cf_department_id" placeholder="请选择" @change="obtainuser" :disabled="editreadonly">
                            <!-- <el-option v-for="(item,index) in optionName" :key="index" :label="item.name" :value="item.id"></el-option> -->
                            <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                                <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-option-group>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="" prop="cf_user_id" class="normal_inp">
                        <el-select v-model="cfollowform.cf_user_id" placeholder="请选择" :disabled="editreadonly">
                            <el-option v-for="(item,index) in usertypes" :key="index" :label="item.u_username" :value="item.u_id"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="看房房源" v-if="cfollowform.cf_fllow_type == 3">
                        <el-input placeholder="请选择" :value="choose_info_str" class="normal_inp" style="width:384px;" readonly>
                            <el-button slot="append" @click="choose_housing" :disabled="editreadonly">选择</el-button>
                        </el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="跟进内容" prop="cf_content">
                        <el-input type="textarea" v-model="cfollowform.cf_content" class="normal_inp" :readonly="editreadonly"></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="下次提醒" prop="cfs_remind_time">
                        <el-date-picker v-model="cfollowform.cfs_remind_time" type="date" placeholder="选择日期" class="normal_inp" value-format="yyyy-MM-dd" @change="changedate" :disabled="editreadonly"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="提醒范围" prop="cfs_user_id">
                        <el-select v-model="cfollowform.cfs_user_id" placeholder="请选择" class="normal_inp" :disabled="!remind">
                            <el-option v-for="(item,index) in cfs_user" :key="index" :label="item.value" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="提醒内容" prop="cfs_content">
                        <el-input type="textarea" v-model="cfollowform.cfs_content" class="normal_inp" :readonly="!remind"></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="" prop="cfs_deal_with">
                        <el-checkbox v-model="cfollowform.cfs_deal_with" :true-label="1" :false-label="2" @change="dealchange" :disabled="business == 3">我知道了</el-checkbox>
                    </el-form-item>
                    <el-form-item label="处理" prop="cfs_dealwith_pro">
                        <el-input class="normal_inp" v-model="cfollowform.cfs_dealwith_pro" readonly></el-input>
                    </el-form-item>
                    <el-form-item label="" prop="cfs_dealwith_time">
                        <el-input class="normal_inp" v-model="cfollowform.cfs_dealwith_time" readonly></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="经理点评" prop="cfs_manager_review">
                        <el-input type="textarea" v-model="cfollowform.cfs_manager_review" class="normal_inp" :readonly="managerReview"></el-input>
                    </el-form-item>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer" v-if="this.resourcesdata == 1 || this.business == 1">
                <el-button @click="gjcancel('followform')" size="mini">取 消</el-button>
                <el-button type="primary" @click="gjsubmit('followform')" size="mini">保 存</el-button>
            </div>
            <div slot="footer" class="dialog-footer" v-if="this.resourcesdata == 2 || this.business == 2">
                <el-button @click="gjcancel('cfollowform')" size="mini">取 消</el-button>
                <el-button type="primary" @click="gjsubmit('cfollowform')" size="mini">保 存</el-button>
            </div>
            <!-- 添加跟进  选择客源 -->
            <el-dialog title="选择客源" :visible.sync="choosekydialogTableVisible" v-if="this.resourcesdata == 1 || this.business == 1" append-to-body>
                <!-- typedata: 1为房源，2为客源-->
                <Chooselist :typedata="1" @choose_info_strs="chooseievent" />
            </el-dialog>
            <!-- 添加跟进  选择房源 -->
            <el-dialog title="选择房源" :visible.sync="choosekydialogTableVisible" v-if="this.resourcesdata == 2 || this.business == 2" append-to-body>
                <!-- typedata: 1为房源，2为客源-->
                <Chooselist :typedata="2" @choose_info_strs="chooseievent" />
            </el-dialog>
        </div>
    </div>
</template>

<script>
    import conf from '../../../../config/userconf.js'
    import permconfig from "../../../../config/permconfig.js"
    export default {
        name: "Editfollow",
        props: {
            followsearch: {//Object类型，必须是定义过的，可以是空字符串""
                type: Object,
                required: true,
            },
            classdata: { //1为添加跟进，2为修改跟进
                type: Number,
                required: true,
            }, 
            resourcesdata: {   //1为房源，2为客源
                type: Number,
                required: true,
            },
            parentid: {   //房客源id
                type: Number,
                required: true,
            },
            permissionFollow: {  //看客户不必写跟进  权限  0为要写，1为不写
                type: Number,
                required: true,
            },
        },
        data () {
            var validatePhone = (rule,value,callback) => {    //正则手机号

                var MobileRegex = /^1[3|4|5|7|8][0-9]{9}$/;
                if (!MobileRegex.test(value)) {
                    callback(new Error('手机号格式不正确！'))
                } else {
                    callback();
                }
            };
            var isCardNo = (rule,value,callback) => {    //正则身份证
                                    
                var MobileRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                // var MobileRegex = /(^\d{14}[[0-9],0-9xX]$)|(^\d{17}[[0-9],0-9xX]$)/;
                if (!MobileRegex.test(value)) {
                    callback(new Error('身份证格式不正确！'))
                } else {
                    callback();
                }
            };
            return {
                transaction: 1,// 交易类型  1 出租、2 出售 、3 租售
                // options: '',  //所有下拉数据
                // customeroptlist: '',  //客源下拉数据
                optionName: [],
                usertypes: [],
                // usertypess: [],
                r_id: '',  // 房源id
                c_id: '',  // 客源id
                property_number: '',  //房源编号
                c_numbering: '',  // 客源编号
                c_user_name: '',  // 客源  客户名称
                followform: {  //房源跟进表单
                    f_user_id: '',
                    f_department_id: '',
                    f_follow_up_way: '',
                    f_content: '',
                    f_customers_id: '',
                    cfs_remind_time: '',
                    cfs_type: 1,   //类型（1房源提醒 2客源提醒）
                    cfs_user_id: '',
                    cfs_content: '',
                    cfs_deal_with: 2,  //	处理结果（1已处理 2未处理）
                    cfs_dealwith_pro: '',
                    cfs_dealwith_time: '',
                    cfs_manager_review: '',
                },
                followrules: {  //房源跟进表单规则
                    f_user_id: [
                        { required: true, message: '请选择跟进人', trigger: 'change' }
                    ],
                    f_department_id: [
                        { required: true, message: '请选择跟进人所在部门', trigger: 'change' }
                    ],
                    f_follow_up_way: [
                        { required: true, message: '请选择跟进方式', trigger: 'change' }
                    ],
                    f_content: [
                        { required: true, message: '请输入跟进内容', trigger: 'blur' },
                        { min: 6, message: '最少输入6个字符', trigger: 'blur' }
                    ],
                },
                cfollowform: {  //客源跟进表单
                    cf_fllow_type: '',
                    cf_room_id: '',
                    cf_content: '',
                    cf_user_id: '',
                    cf_department_id: '',
                    cfs_type: 2,   //类型（1房源提醒 2客源提醒）
                    cfs_user_id: '',
                    cfs_remind_time: '',
                    cfs_content: '',
                    cfs_deal_with: 2,  //	处理结果（1已处理 2未处理）
                    cfs_dealwith_pro: '',
                    cfs_dealwith_time: '',
                    cfs_manager_review: '',
                },
                cfollowrules: {  //客源跟进表单规则
                    cf_user_id: [
                        { required: true, message: '请选择跟进人', trigger: 'change' }
                    ],
                    cf_department_id: [
                        { required: true, message: '请选择跟进人所在部门', trigger: 'change' }
                    ],
                    cf_fllow_type: [
                        { required: true, message: '请选择跟进方式', trigger: 'change' }
                    ],
                    cf_content: [
                        { required: true, message: '请输入跟进内容', trigger: 'blur' },
                        { min: 6, message: '最少输入6个字符', trigger: 'blur' }
                    ],
                },
                follow_up_way: [   // 房源跟进  跟进方式 下拉选项
                    {value: '去电' , id: '1'},
                    {value: '来电' , id: '2'},
                    {value: '看房' , id: '3'},
                    {value: '勘察' , id: '4'},
                    {value: '来访' , id: '5'},
                    {value: '拜访' , id: '6'},
                    {value: '派单' , id: '7'},
                    {value: '短信' , id: '8'},
                    {value: '邮件' , id: '9'},
                    {value: '信函' , id: '10'},
                    {value: '申请' , id: '11'},
                    {value: '修改' , id: '12' , disabled: true},
                    {value: '保留' , id: '13'},
                    {value: '其他' , id: '14'},
                ],
                cfs_user: [   // 房源跟进  提醒范围  下拉选项
                    {value: '本人' , id: '1'},
                    {value: '本部' , id: '2'},
                ],
                choosekydialogTableVisible: false,   // 客源  弹框
                customerData: [],   // 客源列表
                customerform: {
                    c_secondary_area: '',
                    c_trading_type: '',
                    c_buy_status: '',
                    c_store_id: '',
                    c_employees_id: '',
                    keywords: '',
                },
                housingData: [],   // 房源列表
                housingform: {
                    r_d_id: '',
                    source_uid: '',
                    a_id: '',
                    trading_type: '',
                    status: '',
                    keywords: '',
                },
                remind: false,   //跟进 提醒状态
                tjstatus: 1,  // 页面   1 添加    2 修改
                department_name: '',  //部门name
                staff_name: '',  //员工name
                trading_type_opt: [  //交易类型下拉数据
                    {name: '求购',id: '1'},
                    {name: '求租',id: '2'},
                ],
                roomId: '',   //房id
                customersId: '',   //客id
                resourceType: 0,   //房客提醒类型   0默认  1房源跟进提醒   2客源跟进提醒 
                roomcustomersfollowId: '',  //房客跟进id
                dealuserName: '',   //我知道了    用户名
                choose_info_str: '',   //房客源跟进 跟进方式为看房时   选择房客源  展示数据
                business: 3,  //是否为业务提醒   1房源(业务提醒修改跟进)  2客源（业务提醒修改跟进）    3普通修改
                editreadonly: false,  //是否只读
                managerReview: false,  //经理点评
                initialData: {},//初始数据  
            }
        },
        methods: {
            pagetype(data=Object()){
                console.log(this.followsearch,this.classdata,this.resourcesdata,this.parentid);

                //构造默认员工下拉数据
                // this.usertypes = JSON.parse(window.localStorage.getItem('user_down'));
                // console.log(this.usertypes);

                var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');

                if(this.classdata == 2){   //编辑页
                    if(this.followsearch.type == 1 || this.followsearch.type == 2){  //this.followsearch.type为1或者2时，则为业务提醒。为3，则为普通修改跟进

                        this.editreadonly = true;  //业务提醒时，跟进字段不可修改
                        
                        if(this.followsearch.type == 1){  //房
                            this.resourceType = this.followsearch.type;
                            this.roomId = this.followsearch.id;  //房id
                            this.business = 1;
                        }else if(this.followsearch.type == 2){  //客
                            this.resourceType = this.followsearch.type;
                            this.customersId = this.followsearch.id;  //客id
                            this.business = 2;
                        }
                        this.roomcustomersfollowId = this.followsearch.cfid;  //房客跟进id

                        //获取跟进记录信息
                        data.type = this.followsearch.type;
                        data.id = this.followsearch.cfid;  //房客跟进id
                        conf.room.roomcustomersfollow(data,(state,res)=>{
                            if (state == 'success'&&res.data.code == 0){
                               if(this.resourceType == 1){   //房源跟进提醒

                                    this.obtainuser(res.data.data.f_department_id);

                                    this.followform = res.data.data;   //表单数据赋值
                                    this.followform.f_follow_up_way = this.followform.f_follow_up_way.toString();  //跟进方式
                                    this.followform.cfs_user_id = this.followform.cfs_user_id.toString();  //提醒范围
                                    if(this.followform.cfs_remind_time){  //根据提醒时间 设置提醒范围是否可选
                                        this.remind = true;
                                    }else{
                                        this.remind = false;
                                        this.followform.cfs_remind_time = '';
                                        this.followform.cfs_user_id = '';
                                        this.followform.cfs_content = '';
                                    }

                                    if(this.followform.f_follow_up_way == 3){  //跟进方式为  看房
                                        this.choose_info_str = res.data.data.f_customers_id_info;  //看房客源
                                        this.c_id = res.data.data.f_customers_id;
                                    }

                                    //处理   我知道了  值
                                    if(this.followform.cfs_deal_with == 1){
                                        this.followform.cfs_deal_with = true;
                                    }else if(this.followform.cfs_deal_with == 2){
                                        this.followform.cfs_deal_with = false;
                                    }
                                }else if(this.resourceType == 2){   //客源跟进提醒

                                    this.obtainuser(res.data.data.cf_department_id);
                                    this.cfollowform = res.data.data;   //表单数据赋值
                                    
                                    this.cfollowform.cf_fllow_type = this.cfollowform.cf_fllow_type.toString();  //跟进方式
                                    this.cfollowform.cfs_user_id = this.cfollowform.cfs_user_id.toString();  //提醒范围
                                    if(this.cfollowform.cfs_remind_time){  //根据提醒时间 设置提醒范围是否可选
                                        this.remind = true;
                                    }else{
                                        this.remind = false;
                                        this.cfollowform.cfs_remind_time = '';
                                        this.cfollowform.cfs_user_id = '';
                                        this.cfollowform.cfs_content = '';
                                    }

                                    if(this.cfollowform.cf_fllow_type == 3){  //跟进方式为  看房
                                        this.choose_info_str = res.data.data.cf_room_id_info;  //看房房源
                                        this.r_id = res.data.data.cf_room_id;
                                    }

                                    //处理   我知道了  值
                                    if(this.cfollowform.cfs_deal_with == 1){
                                        this.cfollowform.cfs_deal_with = true;
                                    }else if(this.cfollowform.cfs_deal_with == 2){
                                        this.cfollowform.cfs_deal_with = false;
                                    }
                                }

                                this.remind = false;  //业务提醒时, (下次提醒、提醒范围)  不可修改
                                
                            }else if(state == 'success'&&res.data.code != 0){
                                if(res.data.code == 401){
                                    this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                }else{
                                    this.$message({
                                        type: 'info',
                                        message: res.data.msg
                                    });
                                }
                            }
                        })
                    }else{  //普通修改

                        let followtype;

                        if(this.followsearch.type == 3){  //房
                            this.resourceType = this.followsearch.type;
                            followtype = 1;
                        }else if(this.followsearch.type == 4){  //客
                            this.resourceType = this.followsearch.type;
                            followtype = 2;
                        }
                        this.business = 3;
                        this.roomcustomersfollowId = this.followsearch.cfid;  //房客跟进id

                        //获取跟进记录信息
                        data.type = followtype;
                        data.id = this.followsearch.cfid;  //房客跟进id
                        conf.room.roomcustomersfollow(data,(state,res)=>{
                            if (state == 'success'&&res.data.code == 0){
                                console.log(res);
                                if(this.resourceType == 3){   //房源跟进
                                    
                                    this.obtainuser(res.data.data.f_department_id);
                                    this.initialData.f_department_id = res.data.data.f_department_id;  //编辑跟进  权限
                                    this.initialData.f_user_id = res.data.data.f_user_id;  //编辑跟进  权限
                                    this.initialData.f_created_at = res.data.data.f_created_at;  //编辑跟进  权限
                                    this.followform = res.data.data;   //表单数据赋值
                                    this.followform.f_follow_up_way = this.followform.f_follow_up_way.toString();  //跟进方式
                                     //经理点评权限
                                    if(!permconfig.qx_room_dianpinggenjin(this.initialData)){
                                            this.managerReview = true;
                                     }
                                    if(this.followform.f_follow_up_way == 12 || !permconfig.qx_room_xiugaigenjin(this.initialData)){  //跟进方式为  修改
                                        this.editreadonly = true;  //是否只读
                                    }
                                    if(this.followform.f_follow_up_way == 3){  //跟进方式为  看房
                                        this.choose_info_str = res.data.data.f_customers_id_info;  //看房客源
                                        this.c_id = res.data.data.f_customers_id;
                                    }

                                    this.followform.cfs_user_id = this.followform.cfs_user_id.toString();  //提醒范围
                                    if(this.followform.cfs_remind_time){  //根据提醒时间 设置提醒范围是否可选
                                        this.remind = true;
                                    }else{
                                        this.remind = false;
                                        this.followform.cfs_remind_time = '';
                                        this.followform.cfs_user_id = '';
                                        this.followform.cfs_content = '';
                                    }
                                    //处理   我知道了  值
                                    if(this.followform.cfs_deal_with == 1){
                                        this.followform.cfs_deal_with = true;
                                    }else if(this.followform.cfs_deal_with == 2){
                                        this.followform.cfs_deal_with = false;
                                    }
                                }else if(this.resourceType == 4){   //客源跟进
                                    this.obtainuser(res.data.data.cf_department_id);
                                    this.initialData.cf_department_id = res.data.data.cf_department_id;  //编辑跟进  权限
                                    this.initialData.cf_user_id = res.data.data.cf_user_id;  //编辑跟进  权限
                                    this.initialData.cf_created_at = res.data.data.cf_created_at;  //编辑跟进  权限
                                    this.cfollowform = res.data.data;   //表单数据赋值
                                    this.cfollowform.cf_fllow_type = this.cfollowform.cf_fllow_type.toString();  //跟进方式
                                    //经理点评权限
                                    if(!permconfig.qx_keyuan_dianpinggenjin(this.initialData)){
                                            this.managerReview = true;
                                     }
                                    if(this.cfollowform.cf_fllow_type == 12 || !permconfig.qx_ke_xiugaigenjin(this.initialData)){  //跟进方式为  修改
                                        this.editreadonly = true;  //是否只读
                                    }
                                    if(this.cfollowform.cf_fllow_type == 3){  //跟进方式为  看房
                                        this.choose_info_str = res.data.data.cf_room_id_info;  //看房房源
                                        this.r_id = res.data.data.cf_room_id;
                                    }

                                    this.cfollowform.cfs_user_id = this.cfollowform.cfs_user_id.toString();  //提醒范围
                                    if(this.cfollowform.cfs_remind_time){  //根据提醒时间 设置提醒范围是否可选
                                        this.remind = true;
                                    }else{
                                        this.remind = false;
                                        this.cfollowform.cfs_remind_time = '';
                                        this.cfollowform.cfs_user_id = '';
                                        this.cfollowform.cfs_content = '';
                                    }
                                    //处理   我知道了  值
                                    if(this.cfollowform.cfs_deal_with == 1){
                                        this.cfollowform.cfs_deal_with = true;
                                    }else if(this.cfollowform.cfs_deal_with == 2){
                                        this.cfollowform.cfs_deal_with = false;
                                    }
                                }
                            }else if(state == 'success'&&res.data.code != 0){
                                if(res.data.code == 401){
                                    this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                }else{
                                    this.$message({
                                        type: 'info',
                                        message: res.data.msg
                                    });
                                }
                            }
                        })
                    }
                    

                }else if(this.classdata == 1){  //添加页

                    //添加 权限
                    if(arr.indexOf(permconfig.qx_genjin_benren_tianjia)  > -1){
                        this.usertypes = [{
                            "u_id": parseInt(window.localStorage.getItem('uid')),
                            "u_username":window.localStorage.getItem("uname")
                        }]
                        // console.log(this.usertypes);
                    }else{
                        //构造默认员工下拉数据
                        this.usertypes = JSON.parse(window.localStorage.getItem('user_down'));
                        // console.log(this.usertypes);
                    }

                    if(this.resourcesdata == 1){  //房源
                        this.followform.f_department_id = parseInt(window.localStorage.getItem('did'));
                        this.followform.f_user_id = parseInt(window.localStorage.getItem('uid'));
                    }else if(this.resourcesdata == 2){  //客源
                        this.cfollowform.cf_department_id = parseInt(window.localStorage.getItem('did'));
                        this.cfollowform.cf_user_id = parseInt(window.localStorage.getItem('uid'));
                    }
                    
                }
                
            },
            //我知道了  change
            dealchange(val,data=Object()){
                console.log(val);
                if(val == 1){

                    //请求数据（处理人、当前处理时间）
                    conf.room.dealdata(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            console.log(res);
                            //进行数据操作
                            this.dealuserName = res.data.data.userName;  //当前处理人
                            if(this.resourceType == 1){  //房源跟进提醒
                                this.followform.f_content = this.followform.f_content + '[已提醒：'+ this.dealuserName +']';
                                this.followform.cfs_dealwith_pro = res.data.data.userName;
                                this.followform.cfs_dealwith_time = res.data.data.time;
                            }else if(this.resourceType == 2){  //客源跟进提醒
                                this.cfollowform.cf_content = this.cfollowform.cf_content + '[已提醒：'+ this.dealuserName +']';
                                this.cfollowform.cfs_dealwith_pro = res.data.data.userName;
                                this.cfollowform.cfs_dealwith_time = res.data.data.time;
                            }
                        }else if (state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })
                }else if(val == 2){
                    //取消处理
                    if(this.resourceType == 1){  //房源跟进提醒
                        this.followform.f_content = this.followform.f_content.replace('[已提醒：'+ this.dealuserName +']','');
                        this.followform.cfs_dealwith_pro = '';
                        this.followform.cfs_dealwith_time = '';
                    }else if(this.resourceType == 2){  //客源跟进提醒
                        this.cfollowform.cf_content = this.cfollowform.cf_content.replace('[已提醒：'+ this.dealuserName +']','');
                        this.cfollowform.cfs_dealwith_pro = '';
                        this.cfollowform.cfs_dealwith_time = '';
                    }
                }
                
                
            },
            //接收子组件chooselist
            chooseievent(str,id){
                // console.log(str,id);
                this.choose_info_str = str;
                if(this.resourcesdata == 1){
                    this.c_id = id;
                }else if(this.resourcesdata == 2){
                    this.r_id = id;
                }
                this.choosekydialogTableVisible = false;
            },
            //添加房源跟进
            followup(){
                this.gjdialogFormVisible = true;
            },
            //选择房源
            choose_housing(){
                this.choosekydialogTableVisible = true;
            },
            //取消房客源跟进
            gjcancel(formName){
                this.$refs[formName].resetFields();

                if(this.resourcesdata == 1){  //房源
                    this.followform.f_department_id = parseInt(window.localStorage.getItem('did'));
                    this.followform.f_user_id = parseInt(window.localStorage.getItem('uid'));
                }else if(this.resourcesdata == 2){  //客源
                    this.cfollowform.cf_department_id = parseInt(window.localStorage.getItem('did'));
                    this.cfollowform.cf_user_id = parseInt(window.localStorage.getItem('uid'));
                }

                //传数据至父组件    关闭弹框刷新跟进列表
                this.$emit('followevent','');
            },
            //提交房客源跟进
            gjsubmit(formName,data=Object()){

                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if(this.classdata == 1){  //添加页
                            if(this.resourcesdata == 1){  //房源
                                data = this.followform;
                                data.f_room_id = this.parentid;  //房id
                                
                                if(this.followform.cfs_remind_time){
                                    if(this.followform.cfs_content == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请输入提醒内容',
                                            duration: 1000
                                        });
                                        return;
                                    }else if(this.followform.cfs_user_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择被提醒人',
                                            duration: 1000
                                        });
                                        return;
                                    }
                                }
                                //跟进方式  为看房时  提交该客户的客源id
                                if(this.followform.f_follow_up_way == 3){
                                    // console.log(this.c_id);
                                    if(this.c_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择看房客源',
                                            duration: 1000
                                        });
                                        return;
                                    }else{
                                        data.f_customers_id = this.c_id;   //关联的客源id
                                    }
                                }else{
                                    data.f_customers_id = '';   //关联的客源id
                                    //初始化  已选择的客源编号与姓名   避免影响别处
                                    this.choose_info_str = '';
                                    // this.c_numbering = '';
                                    // this.c_user_name = '';
                                }

                                conf.room.follow(data,(state,res)=>{
                                    if (state == 'success'&&res.data.code == 0){
                                        // console.log(res);
                                        this.$message({
                                            type: 'success',
                                            message: '添加成功!',
                                            duration: 1000
                                        });
                                         if(this.permissionFollow == 0){  //需要写跟进时，存储值做个记号
                                             window.localStorage.setItem("ROOM_PUBLIC_GUEST" + this.parentid , 1);
                                            //传值父组件 添加完跟进 看客户权限更改
                                            this.$emit('addfollowP','');
                                        }
                                        this.$refs['followform'].resetFields();

                                        //默认部门员工为当前操作人
                                        this.followform.f_department_id = parseInt(window.localStorage.getItem('did'));
                                        this.followform.f_user_id = parseInt(window.localStorage.getItem('uid'));

                                        // this.gjdialogFormVisible = false;
                                        //传数据至父组件   修改跟进成功   关闭弹框刷新跟进列表
                                        this.$emit('followevent','');
                                        this.choose_info_str = '';
                                        // this.c_numbering = '';
                                        // this.c_user_name = '';
                                        //传数据至父组件   添加跟进成功   res为返回的数据
                                        // this.$emit('followevent',this.r_id);
                                        // this.followlist();
                                    }else if(state == 'success'&&res.data.code != 0){
                                        if(res.data.code == 401){
                                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                        }else{
                                            this.$message({
                                                type: 'info',
                                                message: res.data.msg
                                            });
                                        }
                                    }
                                })
                            }else if(this.resourcesdata == 2){  //客源
                                data = this.cfollowform;
                                data.cf_c_id = this.parentid;  //客id
                                if(this.cfollowform.cfs_remind_time){
                                    if(this.cfollowform.cfs_content == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请输入提醒内容',
                                            duration: 1000
                                        });
                                        return;
                                    }else if(this.cfollowform.cfs_user_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择被提醒人',
                                            duration: 1000
                                        });
                                        return;
                                    }
                                }
                                //跟进方式  为看房时  提交该房源的房源id
                                if(this.cfollowform.cf_fllow_type == 3){
                                    
                                    if(this.r_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择看房房源',
                                            duration: 1000
                                        });
                                        return;
                                    }else{

                                        data.cf_room_id = this.r_id;   //关联的房源id
                                    }
                                }else{
                                    data.cf_room_id = '';   //关联的房源id
                                    //初始化  已选择的房源信息   避免影响别处
                                    this.choose_room_info = '';
                                }
                                conf.resources.addfollow(data,(state,res)=>{
                                    if (state == 'success'&&res.data.code == 0){
                                        // console.log(res);
                                        this.$message({
                                            type: 'success',
                                            message: '添加成功!',
                                            duration: 1000
                                        });
                                        if(this.permissionFollow == 0){  //需要写跟进时，存储值做个记号
                                            window.localStorage.setItem("CUSTOMER_PUBLIC_GUEST" + this.parentid , 1);
                                            //传值父组件 添加完跟进 看客户权限更改
                                            this.$emit('addfollowP','');
                                        }
                                        this.$refs['cfollowform'].resetFields();

                                        //默认部门员工为当前操作人
                                        this.cfollowform.cf_department_id = parseInt(window.localStorage.getItem('did'));
                                        this.cfollowform.cf_user_id = parseInt(window.localStorage.getItem('uid'));

                                        //传数据至父组件   修改跟进成功   关闭弹框刷新跟进列表
                                        this.$emit('followevent','');
                                        this.choose_room_info = '';

                                    }else if(state == 'success'&&res.data.code != 0){
                                        if(res.data.code == 401){
                                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                        }else{
                                            this.$message({
                                                type: 'info',
                                                message: res.data.msg
                                            });
                                        }
                                    }
                                })
                            }
                        }else if(this.classdata == 2){  //编辑页
                       
                            if(this.resourceType == 1 || this.resourceType == 2){    //业务提醒处理（我知道了）

                                data.cfs_id = this.followsearch.cfs_id;  //提醒Id
                                data.type = this.followsearch.type;  //	(1房源跟进 2客源跟进)
                                data.id = this.followsearch.cfid;  //房源或者客源的跟进ID
                                
                                if(this.followsearch.type == 1){  //房

                                    //经理点评内容
                                    if(this.followform.cfs_manager_review){
                                        data.cfs_manager_review = this.followform.cfs_manager_review;
                                    }else{
                                        data.cfs_manager_review = '';
                                    }

                                }else if(this.followsearch.type == 2){  //客
                                    //经理点评内容
                                    if(this.cfollowform.cfs_manager_review){
                                        data.cfs_manager_review = this.cfollowform.cfs_manager_review;
                                    }else{
                                        data.cfs_manager_review = '';
                                    } 

                                }

                                conf.room.businessprocessing(data,(state,res)=>{
                                    if (state == 'success'&&res.data.code == 0){
                                        // console.log('房源修改跟进',res);
                                        this.$message({
                                            type: 'success',
                                            message: res.data.data,
                                            duration: 1000
                                        });

                                        //传数据给父组件  （业务处理  我知道了）
                                        this.$emit('processingevent','');

                                    }else if(state == 'success'&&res.data.code != 0){
                                        if(res.data.code == 401){
                                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                        }else{
                                            this.$message({
                                                type: 'info',
                                                message: res.data.msg
                                            });
                                        }
                                    }
                                })

                            }else if(this.resourceType == 3){  //房源跟进修改
                                data.f_id = this.followform.f_id;  //跟进id
                                data.f_user_id = this.followform.f_user_id;  //跟进员工id
                                data.f_department_id = this.followform.f_department_id;  //跟进员工部门id
                                data.f_follow_up_way = this.followform.f_follow_up_way;  //跟进方式
                                data.f_customers_id = this.followform.f_customers_id;  //跟进方式为看房时   客源id
                                data.f_content = this.followform.f_content;  //跟进内容
                                data.cfs_user_id = this.followform.cfs_user_id;  //被提醒人id（1本人 2本部）
                                data.cfs_remind_time = this.followform.cfs_remind_time;  //提醒时间
                                data.cfs_content = this.followform.cfs_content;  //提醒内容
                                //处理   我知道了  值
                                if(this.followform.cfs_deal_with == true){   //处理结果
                                    data.cfs_deal_with = 1;
                                }else if(this.followform.cfs_deal_with == false){
                                    data.cfs_deal_with = 2;
                                }
                                data.cfs_dealwith_pro = this.followform.cfs_dealwith_pro;  //处理人id
                                data.cfs_dealwith_time = this.followform.cfs_dealwith_time;  //处理时间
                                data.cfs_manager_review = this.followform.cfs_manager_review;  //经理点评
                               
                                if(data.cfs_remind_time){
                                    if(!data.cfs_content){
                                        this.$message({
                                            type: 'info',
                                            message: '请输入提醒内容',
                                            duration: 1000
                                        });
                                        return;
                                    }else if(!data.cfs_user_id){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择被提醒人',
                                            duration: 1000
                                        });
                                        return;
                                    }
                                }
                                //跟进方式  为看房时  提交该客户的客源id
                                if(data.f_follow_up_way == 3){
                                    
                                    if(this.c_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择看房客源',
                                            duration: 1000
                                        });
                                        return;
                                    }else{
                                        data.f_customers_id = this.c_id;
                                    }
                                }else{
                                    data.f_customers_id = '';
                                    //初始化  已选择的客源编号与姓名   避免影响别处
                                    // this.c_numbering = '';
                                    // this.c_user_name = '';
                                    this.choose_info_str = '';
                                }
                                conf.room.editfollow(data,(state,res)=>{
                                    if (state == 'success'&&res.data.code == 0){
                                        // console.log('房源修改跟进',res);
                                        this.$message({
                                            type: 'success',
                                            message: '修改成功!',
                                            duration: 1000
                                        });
                                        this.$refs['followform'].resetFields();

                                        //默认部门员工为当前操作人
                                        this.followform.f_department_id = parseInt(window.localStorage.getItem('did'));
                                        this.followform.f_user_id = parseInt(window.localStorage.getItem('uid'));

                                        // this.gjdialogFormVisible = false;
                                        // this.c_numbering = '';
                                        // this.c_user_name = '';
                                        this.choose_info_str = '';
                                        //传数据至父组件   添加跟进成功   res为返回的数据
                                        // this.$emit('followevent',this.r_id);
                                        //传数据至父组件   修改跟进成功   关闭弹框
                                        this.$emit('followevent','');
                                        // this.followlist();
                                    }else if(state == 'success'&&res.data.code != 0){
                                        if(res.data.code == 401){
                                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                        }else{
                                            this.$message({
                                                type: 'info',
                                                message: res.data.msg
                                            });
                                        }
                                    }
                                })
                            }else if(this.resourceType == 4){  //客源跟进修改
                                data.cf_id = this.cfollowform.cf_id;  //跟进id
                                data.cf_fllow_type = this.cfollowform.cf_fllow_type;  //跟进方式
                                data.cf_room_id = this.cfollowform.cf_room_id;  //跟进方式为看房时   房源id
                                data.cf_content = this.cfollowform.cf_content;  //跟进内容
                                data.cf_user_id = this.cfollowform.cf_user_id;  //跟进员工id
                                data.cf_department_id = this.cfollowform.cf_department_id;  //跟进员工部门id
                                data.cfs_user_id = this.cfollowform.cfs_user_id;  //被提醒人id（1本人 2本部）
                                data.cfs_remind_time = this.cfollowform.cfs_remind_time;  //提醒时间
                                data.cfs_content = this.cfollowform.cfs_content;  //提醒内容
                                //处理   我知道了  值
                                if(this.cfollowform.cfs_deal_with == true){   //处理结果
                                    data.cfs_deal_with = 1;
                                }else if(this.cfollowform.cfs_deal_with == false){
                                    data.cfs_deal_with = 2;
                                }
                                data.cfs_dealwith_pro = this.cfollowform.cfs_dealwith_pro;  //处理人id
                                data.cfs_dealwith_time = this.cfollowform.cfs_dealwith_time;  //处理时间
                                data.cfs_manager_review = this.cfollowform.cfs_manager_review;  //经理点评
                               
                                if(data.cfs_remind_time){
                                    if(data.cfs_content == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请输入提醒内容',
                                            duration: 1000
                                        });
                                        return;
                                    }else if(data.cfs_user_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择被提醒人',
                                            duration: 1000
                                        });
                                        return;
                                    }
                                }
                                //跟进方式  为看房时  提交该房源的房源id
                                if(data.cf_fllow_type == 3){
                                    
                                    if(this.r_id == ''){
                                        this.$message({
                                            type: 'info',
                                            message: '请选择看房房源',
                                            duration: 1000
                                        });
                                        return;
                                    }else{
                                        data.cf_room_id = this.r_id;
                                    }
                                }else{
                                    data.cf_room_id = '';
                                    //初始化  已选择的房源信息   避免影响别处
                                    // this.choose_room_info = '';
                                    this.choose_info_str = '';
                                }
                                conf.resources.editfollow(data,(state,res)=>{
                                    if (state == 'success'&&res.data.code == 0){
                                        // console.log('客源修改跟进',res);
                                        this.$message({
                                            type: 'success',
                                            message: '修改成功!',
                                            duration: 1000
                                        });
                                        this.$refs['cfollowform'].resetFields();

                                        //默认部门员工为当前操作人
                                        this.cfollowform.cf_department_id = parseInt(window.localStorage.getItem('did'));
                                        this.cfollowform.cf_user_id = parseInt(window.localStorage.getItem('uid'));

                                        // this.gjdialogFormVisible = false;
                                        // this.choose_room_info = '';
                                        this.choose_info_str = '';
                                        //传数据至父组件   修改跟进成功   关闭弹框
                                        this.$emit('followevent','');
                                    }else if(state == 'success'&&res.data.code != 0){
                                        if(res.data.code == 401){
                                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                        }else{
                                            this.$message({
                                                type: 'info',
                                                message: res.data.msg
                                            });
                                        }
                                    }
                                })
                            }

                        }
                        
                        

                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            //跟进方式改变
            changetype(val){
                // console.log(val);
                if(val == 3){  
                    this.followform.f_customers_id = val;
                }else{
                    this.followform.f_customers_id = '';
                }
            },
            //下次提醒日期改变
            changedate(val){
                // console.log(val);
                if(val){
                    this.remind = true;
                }else{
                    this.remind = false;
                    this.followform.cfs_remind_time = '';
                    this.followform.cfs_user_id = '';
                    this.followform.cfs_content = '';
                }
            },
            //获取部门
            obtainName(data=Object()){

                if(this.classdata == 1){  //添加
                    conf.department.nameOpt(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.optionName = res.data.data;
                            // console.log(res); 
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == -404){
                                this.optionName = [];
                            }else if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    }, 'qx_room_tianjiagenjin')
                }else if(this.classdata == 2){  //修改

                    conf.department.nameOpt(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.optionName = res.data.data;
                            // console.log(res); 
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == -404){
                                this.optionName = [];
                            }else if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })
                }
            },
            //获取部门员工(跟进)
            obtainuser(val,data=Object()){
                this.usertypes = [];
                if(this.resourcesdata == 1){  //房源
                    this.followform.f_user_id = '';
                }else if(this.resourcesdata == 2){  //客源
                    this.cfollowform.cf_user_id = '';
                }

                data.d_id = val;
                conf.department.userOpt(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        // console.log(res); 
                        this.usertypes = res.data.data;
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            
        },
        mounted (){
            this.$nextTick(function(){
                this.pagetype();  //页面状态  （修改、添加）
                // this.optlist();  //房源下拉数据
                // this.custoptlist(); //客源下拉数据
                this.obtainName();  //部门下拉
                // this.obtainuser();  //部门员工
            })
        },

    }
</script>